import { createApp } from 'vue'
import { createPinia } from 'pinia'

import App from './App.vue'
import router from './router'

// OpenTiny UI组件库
import TinyVue from '@opentiny/vue'
import '@opentiny/vue-theme/index.css'

// 自定义样式
import './assets/styles/glassmorphism.scss'
import './assets/styles/main.scss'

// 工具库
import nprogress from 'nprogress'
import 'nprogress/nprogress.css'

// 性能监控
import { createPerformancePlugin } from './utils/performance'

// 全局组件注册
import { registerGlobalComponents } from '@/components/global'

const app = createApp(App)

// 配置NProgress
nprogress.configure({ 
  showSpinner: false,
  trickleSpeed: 200,
  minimum: 0.3
})

// 配置性能监控
const isDev = import.meta.env.DEV
app.use(createPerformancePlugin({
  enableTracking: true,
  sampleRate: isDev ? 1.0 : 0.1, // 生产环境降低采样率
  apiEndpoint: isDev ? undefined : '/api/performance', // 生产环境发送到API
  bufferSize: isDev ? 10 : 50,
  flushInterval: isDev ? 10000 : 30000
}))

app.use(createPinia())
app.use(router)
app.use(TinyVue)

// 注册全局组件
registerGlobalComponents(app)

app.mount('#app')
